package com.blog.mapper;

import com.blog.pojo.ArticleTag;
import com.blog.pojo.Tag;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleTagMapper {

    /**
     * 查看文章的所有标签
     * @param id 文章id
     * @return 标签列表
     */
    @Select("select t.* from tag t " +
            "join article_tag at on t.id = at.tag_id " +
            "where at.article_id = #{id}")
    List<Tag> listByArticleId(Integer id);

    /**
     * 删除文章标签
     * @param articleId 文章id
     */
    @Delete("delete from article_tag " +
            "where article_id = #{articleId}")
    void deleteByArticleId(Integer articleId);

    /**
     * 新增文章标签
     * @param articleTag 文章标签实体类
     */
    @Insert("insert into article_tag (article_id, tag_id) values (#{articleId}, #{tagId})")
    void insert(ArticleTag articleTag);


}
